package com.baoming.util;

import java.io.IOException; 
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 

public class PageFileter implements Filter{
 
	public void destroy() {
		
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) servletRequest;
		HttpServletResponse response = (HttpServletResponse) servletResponse; 
		String path = request.getServletPath();  
	  
		if(path.contains("font") || 
				path.contains("m_login")||
				path.contains("m_checkManager")|| 
				path.contains("m_main")){
			chain.doFilter(request, response);
			return;  
		}else{
			Object global_manager = request.getSession().getAttribute("globalManager") ; 
			if(global_manager == null){
				response.sendRedirect(request.getContextPath()+"/");
			}else{
				chain.doFilter(request, response);
				return;  
			}
		} 
		
	}

	public void init(FilterConfig arg0) throws ServletException {
		 
	}

}
